<template>
  <div>
    <Breadcrumb>
      <BreadcrumbItem>首页</BreadcrumbItem>
      <BreadcrumbItem>优惠券数据统计</BreadcrumbItem>
    </Breadcrumb>
    <Form ref="formInline" :model="request" inline>
      <FormItem>
        优惠券ID:<Input type="text" v-model="request.username" clearable placeholder="请输入ID名称" style="width: 120px;" />
      </FormItem>
      <FormItem>
        领券类型:<Select  placeholder="请选择" style="width: 120px;"  >
                  <Option value="0">全部</Option>
                  <Option value="1">分享领券</Option>
                  <Option value="1">直接领券</Option>
                  <option value="2">下单返券</option>
                </Select>
      </FormItem>
      <FormItem>
        统计时间:<DatePicker
        type="daterange"
        v-model="params.device_time"
        @on-change="timechange"
        :transfer="true"
        placement="bottom-end"
        placeholder="请选择开始-结束时间"
        style="width: 200px"
      ></DatePicker>
      </FormItem>
      <FormItem>
        <Button type="primary" @click="search" style="margin-right: 10px"
        >搜索</Button
        >
      </FormItem>
    </Form>

    <div>
      <Table :columns="columns1" :data="data" :height="height">
        <template slot-scope="{ row }" slot="status">
          <span class="success" v-if="row.status === '1'">正常</span>
          <span class="error" v-else>异常</span>
        </template>
        <template slot-scope="{ row }" slot="order_name">
          <span>{{ row.order_name[0] }}</span>
        </template>
        <template slot-scope="{ row }" slot="is_push">
          <span class="success" v-if="row.is_push == 2">完成</span>
          <span class="error" v-else>未完成</span>
        </template>
        <template slot-scope="{ row }" slot="option">
          <Button
            type="primary"
            size="small"
            style="margin-right: 5px"
            v-hasPermission="['37']"
            @click="add3"
          >查看</Button
          >
        </template>
      </Table>
    </div>

    <div style="display: flex; justify-content: center; margin-top: 24px">
      <Page style="display: flex;justify-content: center;margin-top: 24px;" :total="page.count" :page-size="20" :page-size-opts="[20,30,40,50,100]" show-elevator show-sizer show-total
            @on-change="handleCurrentChange" @on-page-size-change="handleSizeChange" />

    </div>
    <Modal v-model="modal3"    :mask-closable="false" width="1000" >
      <Form :label-width="110">
        <div><h4 class="door_device">查看详情</h4></div>
        <Table height="200" :columns="columns2" :data="data2">
        </Table>
        <Page style="display: flex;justify-content: center;margin-top: 24px;" :total="page.count" :page-size="20" :page-size-opts="[20,30,40,50,100]" show-elevator show-sizer show-total
              @on-change="handleCurrentChange" @on-page-size-change="handleSizeChange" />
      </Form>
    </Modal>
  </div>


</template>

<script>
  export default {
    data() {
      return {
        params: {
          device_time: [],
          status: 1,
          user_id: "",
          order_id: "",
          activity_id: "",
          page: 1,
          limit: 10,
        },
        total: 0,
        page: {},
        height: this.$store.state.height,
        modal1: false,
        modal3: false,
        data1: [
          {
            id: 1,
            title: "机器组3",
          },
          {
            id: 2,
            title: "机器组4",
          },
        ],
        request: {
          device_number: "",
          page: 1,
        },
        columns1: [
          {
            title: "优惠券ID",
            key: "coupon_id",
            minWidth: 150,
            align: "center"
          },
          {
            title: "优惠券名称",
            key: "coupon_name",
            minWidth: 300,
            align: "center"
          },
          {
            title: "优惠券时间",
            key: "coupon_times",
            minWidth: 150,
            align: "center"
          },

          {
            title: "优惠券类型",
            key: "coupon_types",
            minWidth: 150,
            align: "center",
          },
          {
            title: "总发券量",
            key: "total_coupon",
            minWidth: 150,
            align: "center",
          },
          {
            title: "领取人数",
            key: " recipients",
            minWidth: 150,
            align: "center",
          },
          {
            title: "领取张数",
            key: "counts",
            minWidth: 150,
            align: "center",
          },
          {
            title: "用券人数",
            key: "use_coupons",
            minWidth: 150,
            align: "center",
          },
          {
            title: "用券订单数",
            slot: "usecoupon_counts",
            minWidth: 160,
            align: "center",
          },
          {
            title: "用券实付交易额",
            key: "coupon_price",
            minWidth: 150,
            align: "center",
          },
          {
            title: "用券原价交易额",
            slot: "origin_price",
            minWidth: 160,
            align: "center",
          },
          {
            title: "总补贴金额",
            key: "all_price",
            minWidth: 150,
            align: "center",
          },
          {
            title: "操作",
           key:'option',
            minWidth: 160,
            align: "center",
          }

        ],
        data: [],
        columns2: [
          {
            title: "活动ID",
            key: "user_id",
            minWidth: 150,
            align: "center"

          },
          {
            title: "活动名称",
            key: "activity_name",
            minWidth: 300,
            align: "center"
          },
          {
            title: "活动有效名称",
            key: "useful_name",
            minWidth: 150,
            align: "center"
          },

          {
            title: "活动类型",
            key: "activity_types",
            minWidth: 150,
            align: "center",
          },
          {
            title: "已优惠金额",
            key: "discount_price",
            minWidth: 150,
            align: "center",
          },
          {
            title: "参与该活动订单量",
            key: "activity_counts",
            minWidth: 150,
            align: "center",
          },
          {
            title: "拉新",
            key: "news",
            minWidth: 150,
            align: "center",
          },
          {
            title: "参与活动的用户数",
            key: "user_counts",
            minWidth: 150,
            align: "center",
          }
        ],
        data2: [
          {
            user_id: 1,
            order_id:'2019089898',
            device_id:'康师傅冰红茶柠檬味瓶装500mlx1',
            device_name:'B8370',
            device_time:'0.75',
            belong_shop:'2021-09-18 14:38:15',
            order_counts:'123',
            customer_price:'123',
            total_price:'234',
            before_price:'999',
            discount_price:'10000'
          },
          {
            user_id: 2,
            order_id:'2019089898',
            device_id:'康师傅冰红茶柠檬味瓶装500mlx1',
            device_name:'B8370',
            device_time:'0.75',
            belong_shop:'2021-09-18 14:38:15',
            order_counts:'123',
            customer_price:'123',
            total_price:'234',
            before_price:'999',
            discount_price:'10000'
          },
          {
            user_id: 3,
            order_id:'2019089898',
            device_id:'康师傅冰红茶柠檬味瓶装500mlx1',
            device_name:'B8370',
            device_time:'0.75',
            belong_shop:'ijooz',
            order_counts:'123',
            customer_price:'123',
            total_price:'234',
            before_price:'999',
            discount_price:'10000'
          }
        ],
        role_id:null,
      };
    },
    mounted() {

      this.init();
    },
    methods: {
      add3(){
        this.cancel();
        this.modal3 = true
        this.allocated = [];
        this.undistributed = [];
        if(this.infoID == 6){
          console.log('6')
          this.axios.post("device/getAllDev").then(res => {
            if (res.code == 1) {
              this.allocated = res.data.allocated;
              this.undistributed= res.data.undistributed;
            }
          });

        }
      },
      init() {
        this.axios.post("order/order_list", this.params).then((res) => {
          console.log("this.params: ", this.params);
          if (res.code == 1) {
            console.log(res);
            this.total = res.data.count;
            this.tableData = res.data.list;
          }
        });
      },
      search() {
        this.params.page = 1;
        this.init();
      },
      confirm() {
        this.modal1 = false;
        this.$Message.success("保存成功！");
        this.cancel();
      },
      cancel() {},
      add() {
        this.modal1 = true;
      },
      setStatus(id, status) {
        var text = "确定要" + (status == 1 ? "启用" : "禁用") + "此机器组么？";
        this.$Modal.confirm({
          title: text,
          onOk: () => {
            this.$Message.success("操作成功");
          },
          onCancel: () => {},
        });
      },
      lists() {},
      timechange(val) {
        console.log(val);
      },
      handleSizeChange(val) {
        this.request.page = 1;
        this.request.limit = val;
        this.lists();
      },
      handleCurrentChange(val) {
        this.params.page = val;
        this.init();
      },
    },
  };
</script>

<style>
  *{
    margin: 0;
    padding: 0;
  }
  .door_device{
    position: relative;
    top: -20px;
  }
  .words{
    color: rgb(250, 100, 20);
    font-weight: bold;
    font-size: 20px;
  }
</style>
